package com.taotao.health.service.impl;

import com.taotao.common.core.domain.Result;
import com.taotao.common.security.utils.SecurityUtils;
import com.taotao.health.domain.vo.DoctorCreationsVO;
import com.taotao.health.domain.vo.DoctorsPatientVO;
import com.taotao.health.mapper.CreateMapper;
import com.taotao.health.service.CreateService;
import com.taotao.system.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class CreateServiceImlp implements CreateService {

    @Autowired
    private CreateMapper createMapper;


    // 新增文章
    @Override
    public Result increaseArticle(DoctorCreationsVO doctorCreationsVO) {
        //对数据进行非空校验
        if (doctorCreationsVO.getTitle() == null || doctorCreationsVO.getContent() == null) {
            return Result.error("标题或内容不能为空");
        }
        //对数据进行非空校验
        if (doctorCreationsVO.getCoverImage() == null) {
            doctorCreationsVO.setCoverImage("https://img.zcool.cn/community/01f15c5a0f8f1fa801206c2d0e0c9a.jpg@1280w_1l_2o_100sh.jpg");
        }
        //对数据进行非空校验
        if (doctorCreationsVO.getArticleVideo() == null) {
            doctorCreationsVO.setArticleVideo(0);
        }
        createMapper.increaseArticle(doctorCreationsVO);
        return Result.success("添加成功");
    }

    // 查询文章草稿
    @Override
    public List<DoctorCreationsVO> selectDoctorDraft() {
        //获取登录人id
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long doctorId = loginUser.getUserid();
        List<DoctorCreationsVO> doctorCreationsVOS = createMapper.selectDoctorDraft(doctorId);
        return doctorCreationsVOS;
    }

    // 修改文章
    @Override
    public Result updateArticleById(DoctorCreationsVO doctorCreationsVO) {
        createMapper.updateArticleByIds(doctorCreationsVO);
        return Result.success("修改成功");
    }

    // 删除文章
    @Override
    public Result deleteArticleById(Integer creationId) {
        createMapper.deleteArticleById(creationId);
        return Result.success("删除成功");
    }

    // 查询医生发布的文章
    @Override
    public List<DoctorCreationsVO> selectDoctorArticle() {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long doctorId = loginUser.getUserid();
        List<DoctorCreationsVO> doctorCreationsVOS = createMapper.selectDoctorArticle(doctorId);
        return doctorCreationsVOS;
    }

    // 查询文章详情
    @Override
    public List<DoctorCreationsVO> selectArticleById(Integer creationId) {
        List<DoctorCreationsVO> doctorCreationsVOS = createMapper.selectArticleById(creationId);
        return doctorCreationsVOS;
    }

    // //查询医生手下的患者信息
    @Override
    public List<DoctorsPatientVO> selectDoctorPatient() {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long doctorId = loginUser.getUserid();
        List<DoctorsPatientVO> doctorsPatientVOS = createMapper.selectDoctorPatient(doctorId);
        return doctorsPatientVOS;

    }

    // 修改患者状态
    @Override
    public Result updateDoctorConsultationStatus(Integer id) {
        createMapper.updateDoctorConsultationStatus(id);
        return Result.success("修改成功");
    }

    // 修改患者原因
    @Override
    public Result updateDoctorConsultationReason(Integer id, Integer reason) {
        createMapper.updateDoctorConsultationReason(id,reason);
        return Result.success("修改成功");
    }
    /**
     * 查看所有列表
     * @return
     */
    @Override
    public List<DoctorCreationsVO> All(DoctorCreationsVO doctorCreationsVO) {
        return createMapper.All(doctorCreationsVO);
    }



}
